using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class FollowPlayer : MonoBehaviour
{
    private NavMeshAgent agent;
    public QuestData_SO currentQuest;
    public Transform pos;
    private Animator anim;


    private void Awake()
    {
        agent = GetComponent<NavMeshAgent>();
        anim = GetComponent<Animator>();
    }

    private void Update()
    {
        SwitchAnim();
        if (QuestManager.Instance.GetTask(currentQuest) != null)
        {
            if (QuestManager.Instance.GetTask(currentQuest).IsStarted)
            {
                if (QuestManager.Instance.GetTask(currentQuest).IsFinished)
                {
                    agent.destination = pos.position;
                }
                else
                {
                    agent.destination = GameManager.Instance.playerStats.transform.position;
                }
            }
        }
    }

    public void SwitchAnim()
    {
        anim.SetFloat("Speed", agent.velocity.sqrMagnitude);
    }
}
